package day0;

import java.util.Scanner;

import org.junit.Test;

public class HomeWork {

	@Test
	public void test1() {
		// 定义输入----单价、数量、金额
		// 定义输出----应收金额、找零
		// 使用double类型变量
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入单价：");
		// scnner cannot be resolved
		double unitPrice = scanner.nextDouble();
		System.out.println("请输入数量:");
		int count = scanner.nextInt();
		double totalPrice = unitPrice * count;
		System.out.println("总价是：" + totalPrice);
		if (totalPrice >= 500) {
			totalPrice = totalPrice * 0.8;
		}
		System.out.println("打折后应收金额：" + totalPrice);
		System.out.println("请用户付钱：");
		double inputPrice = scanner.nextDouble();
		double returnPrice = inputPrice - totalPrice;
		if (returnPrice > 0) {
			System.out.println("应找零：" + returnPrice);
		} else if (returnPrice < 0) {
			System.out.println("给的钱不够");
		} else {
			System.out.println("钱正好");
		}
	}
	
//	计算9的阶乘 9!=9*8*7*6...*2*1
	@Test
	public void test2() {
		int num = 9;
		int sum = 1;
		for (int i = 1; i <= 9; i++) {
			System.out.println(i);
			sum = sum * i;
		}
		System.out.println(sum);
		// Duplicate local variable num
		// int num = 8;
		System.out.println("-----------");
		// i,j,k
		for (int i = 9; i >= 1; i--) {
			System.out.println(i);
		}
	}
	
	@Test
	public void test3() {
		// 用for循环输出1—1000之间能被5整除的数，且每行输出3个
		int count = 0;
		for (int i = 1; i <= 1000; i++) {
			if (i % 5 == 0) {
				System.out.print(i + "\t");
				count = count + 1;
				
				// 加1之后要看一下是不是已经打印了三个了
				if (count == 3) {
					System.out.println();
					count = 0;
				}
			}
		}
	}
	
	@Test
	public void test4() {
		// 用for循环输出1—1000之间能被5整除的数，且每行输出3个
		int count = 0;
		for (int i = 1; i <= 1000; i++) {
			if (i % 5 == 0) {
				System.out.print(i + "\t");
				count = count + 1;
				
				// 加1之后要看一下是不是已经打印了三个了
				if (count % 3 == 0) {
					System.out.println();
				}
			}
		}
	}
	
	@Test
	public void test5() {
		// 用for循环输出1—1000之间能被5整除的数，且每行输出3个
		int count = 0;
		for (int i = 1; i <= 1000; i++) {
			if (i % 5 == 0) {
				System.out.print(i + "\t");
				count = count + 1;
			}

			// 加1之后要看一下是不是已经打印了三个了
			if (count % 3 == 0 /* && i % 5 == 0 */) {
				System.out.println();
			}
		}
	}
	
	// 计算1-100以内所有奇数的和以及所有偶数的和，分别打印出来。
	@Test
	public void test15() {
		int oddSum = 0;
		int evenSum = 0;
		for (int i = 1; i <= 100; i++) {
			if (i % 2 ==  0) {
				evenSum = evenSum + i;
			} else {
				oddSum = oddSum + i;
			}
		}
		
		System.out.println("奇数和：" + oddSum);
		System.out.println("偶数和：" + evenSum);		
	}
	
	// 1*9=9   2*9=18   3*9=27 ....   8*9=72  9*9=81 (用while和for分别实现)  print()只打印不换行
	@Test
	public void test6() {
		for (int i = 1; i <= 9; i++) {
			System.out.print(i + "*9=" + (i * 9) + "   ");
		}
	}
	
	@Test
	public void test7() {
		int i = 1;
		while (i <= 9) {
			System.out.print(i + "*9=" + (i * 9) + "   ");
			i++;
		}
	}
	
	// *****
	@Test
	public void test8 () {
		for (int i = 1; i <= 5; i++) {
			System.out.print("*");
		}
		System.out.println();
		// *
		// *
		// *
		// *
		// *
		for (int i = 1; i <= 5; i++) {
			System.out.println("*");
		}
		System.out.println("-----------------------------");
		// 外层循环是控制打印行数,只要数一下有几行
		for (int i = 1; i <= 5; i++) {
			// 内层循环控制这一行打印所少个，需要根据外层循环找一下规律
			for (int j = 1; j <= i; j++) {
				System.out.print(j);
			}
			// 打印完一行之后要换行
			System.out.println();
		}
		// i=1      j=1
		// i=2      j=2
		// i=3      j=3
	}
	
	// 从控制台输入两个数,然后分别打印这两个数，然后交换这两个数的值
	@Test
	public void test9() {
		int num1 = 3;
		int num2 = 5;
		System.out.println("num1 before: " + num1);
		System.out.println("num2 before: " + num2);
		
		int temp = num1;
		num1 = num2;
		num2 = temp;
		
		System.out.println("num1 after: " + num1);
		System.out.println("num2 after: " + num2);
	}
	
	@Test
	public void test10() {
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入利润：");
		double profit = scanner.nextDouble();
		double bonus = 0;
		if (profit >= 0 && profit <= 10) {
			bonus = profit * 0.1;
		} else if (profit > 10 && profit < 20) {
			bonus = 10 * 0.1 + (profit - 10) * 0.075;
		} else if (profit >= 20 && profit < 40) {
			bonus = 10 * 0.1 + 10 * 0.075 + (profit - 20) * 0.05;
		}
		// The local variable bonus may not have been initialized(初始化)
		System.out.println("奖金：" + bonus);
	}
	
}
